from pymongo import MongoClient

# 源client
client = MongoClient('mongodb://admin:yzy%40123456@10.11.2.56:27017/')
# 源数据库
origin_db = client["algorithm"]
origin_collection = origin_db['western_element_score']
results = origin_collection.find()

my_dict = {}
for result in results:
    # 添加一个键值对
    my_dict.update({result["name"]: result["code"]})
# 输出字典
# print(my_dict)

origin_collection_1 = origin_db['western_temp_data']
results_list = origin_collection_1.find()
for result in results_list:
    # 添加一个键值对
    element_list = result['element'].split("，")
    element_code_list = []
    element_name_list = []
    for item in element_list:
        element_code_list.append({"code": my_dict.get(item), "name": item, "score": 1})
        element_name_list.append(item)
    print(result['syndrome'], element_name_list, element_code_list)
#
# # 根据字段查询数据
# query = {"requestId": "ddaa9c32-de4e-4174-999a-a32de423d59b"}
# results = origin_collection.find(query)
#
# # y_data1 = []
# # # 打印查询结果
# # for result in results:
# #     print("1", result["explain"])
# #     expalins = result["explain"]
# #     for item in expalins:
# #         y_data1.append(item["score"])
#
# y_data2 = []
# # 准备数据
# x_data = []
# # 根据字段查询数据
# query = {"requestId": "8d0179c9-2bba-408d-ab11-73ed1f4be5e6"}
# results1 = origin_collection.find(query)
# for result in results1:
#     print("2", result["explain"])
#     expalins = result["explain"]
#     for item in expalins:
#         x_data.append(item["name"])
#         y_data2.append(item["score"])
#
# # 创建ECharts对象
# line = Line()
#
# # 添加数据和配置项
# line.add_xaxis(x_data)
# # line.add_yaxis("第一次", y_data1)
# line.add_yaxis("第二次", y_data2)
# line.set_global_opts(title_opts=opts.TitleOpts(title="西医折线图"))
# # 渲染图表并保存为HTML文件
# line.render("double_line_example.html")
